Repository navigation
node: --decryptkey (and docker decrypt-key) turns a password-encrypted key into the plain key - #175
Merged
Merged
Conversation
…cker or native) A new section 10 for operators who keep an identity they already have: a plain key in the native folder before the set-up, an encrypted key on a console (not under systemd), a plain key in Docker (~/.credits/keys, uid 1000, mode 600; the container makes keys only when keys/NodePublic.txt is missing), and an encrypted key in Docker, converted once with the image's own node --dumpkeys. Also the native conversion for systemd. Troubleshooting becomes section 11. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d key into the plain key --decryptkey asks the password of the private key file the node encrypted (the same prompt and retries as a start), checks that the key matches the public key file, keeps the encrypted file as <private>.encrypted-YYYYMMDD-HHMMSS (mode 0600, created new, never overwriting), writes the plain key in place with the atomic key-file writer of #170 and exits. A plain key is left as it is (exit 0). It reads no configuration and opens no network or database; it refuses while db/.lock is held. The file format is the plain one the node already reads; no new crypto. writeKeyFile moves to keyfilecrypt.cpp with the new cs::keyfile::toPlain; the password loop of readKeys becomes unlockWithPrompt, shared by both. Docker: `docker compose run --rm node decrypt-key` runs it on /data/keys; a normal start with an encrypted key now stops with that command instead of waiting for a password. quick-start.md section 10 and the Docker README use these steps instead of the --dumpkeys procedure. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of #175. M1: usePassword() looped forever once stdin was at its end (cin >> choice failed and left the choice empty). It now returns, and its callers stop: --decryptkey < /dev/null prints "Cancelled" and exits 1, and a start with an encrypted key and no input (systemd) exits instead of flooding the log. M2: the password was read with getchar() after the choice was read with std::cin, which under sync_with_stdio(false) had already buffered the piped input, so a password piped with the choice was never seen. On Linux and macOS the password is now read from std::cin. The echo and the line editing are off for the whole read on a terminal, and the prompt is printed after that, so nothing typed after it is echoed. The end of the choice's line is skipped. Windows keeps its console read. L2: writeKeyFile removes whatever has the .tmp name and creates it new (O_EXCL; CREATE_NEW on Windows): a stale file is not reused, a link not followed, a FIFO not waited on. L5: decrypt() can report a failed derivation (no memory), and the prompt then says that libsodium needs about 1 GB instead of "Incorrect password", and does not ask again. Tests: the end of input cancels (several inputs); a choice and a password piped at once open the key (not on Windows); a failed derivation is told apart from a wrong password. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- L1: stop every node that uses the key first, an official one or one on another machine too. - L3: on Windows, type the password in a console, and the files keep the folder's permissions. - L5: opening the key needs about 1 GB free, so CREDITS_MEMORY must be at least about 1.2g. - L6: with an encrypted key the container keeps restarting until it is stopped. - The Docker README snippet saves the keys the container made, and shows the piped form. - The entrypoint test says what its stub checks, and points to the unit tests for the node's own reading of the input. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One command turns a node key encrypted with a password (
--encryptkey, or the password choice at the first start) into the plain key file, after the old password is typed. It replaces the--dumpkeys+ python + shred procedure.Docker
Native (node stopped, in the
csnodefolder):./node --decryptkey(Windows:node.exe --decryptkey)What
--decryptkeydoes--public-key-fileand--private-key-file, by defaultNodePublic.txtandNodePrivate.txt.p/f,Enter password:) and asks again after a wrong one, as at a start. Then it:NodePublic.txtand refuses otherwise (also when the file is missing; that check runs before the password is asked);NodePrivate.txt.encrypted-YYYYMMDD-HHMMSS, mode 0600. The file is created new and never overwrites anything; if the name is taken,-2,-3, ... is added;keygen.pyalready write;NodePrivate.txt is now in clear (address <base58 public key>); the encrypted original is kept as <file>and exits without starting the node.db/.lockis held (a running community node). It reads noconfig.iniand needs no network, database or executor. It runs right after--working_dir, before the configuration is read.cs::keyfile::decryptfrom config: safer handling of the encrypted key file (atomic re-encryption, clear errors; format unchanged) #170. The secret buffers are zeroed.writeKeyFilemoved tokeyfilecrypt.cppbeside the newcs::keyfile::toPlain. The password loop ofreadKeysis nowunlockWithPrompt, which both use, so a start behaves as before.Docker
entrypoint.shtakes the commanddecrypt-key. It runsnode --decryptkeyon/data/keyswith the terminal's input and exits, without writing a config or downloading anything. Any other command is refused with exit 2.keys/NodePrivate.txtthat decodes to 88 bytes now stops the container (exit 3) with a message that points todocker compose run --rm node decrypt-key. Before, the node waited for a password that nobody could type.Docs
docs/quick-start.mdrewritten: "Docker, encrypted key" and "Convert an encrypted key to plain" now usedecrypt-key/--decryptkey. The warnings stay: never two nodes with one key, an offline backup of the original, and a plain key is as exposed as the machine. Merging this PR merges docs: quick-start: using an existing node key (plain or encrypted, Docker or native) #174 too.Review fixes (76afbb6, 57e0dd1)
--decryptkey < /dev/nullprints "Cancelled" and exits 1, and a start under systemd with an encrypted key exits.std::cin, so a password piped with the choice now works:printf 'p\n%s\n' "$PW" | docker compose run --rm -T node decrypt-key..tmpfile is created new with O_EXCL, after removing whatever had that name.< /dev/null; piped input on the real community.17 image with the new binary; a pty session (no password echo); a low-memory run underulimit -v.Tests
KeyFileCryptToPlain.*, in thekeyfilecrypt_testsctest entry, whose filter is nowKeyFileCrypt*):NodePublic.txtis refused;NodePublic.txtmatches;packaging/docker/test/test-entrypoint.shcase 17:decrypt-keygets the right arguments and stdin;decrypt-keywithout keys, and an unknown command, are refused.keygen.py, encrypted by the node itself with--encryptkey, then--decryptkeywith one wrong password and then the right one. The plain file is identical to the original, and the backup is identical to the encrypted file. A plain key, a helddb/.lock(exit 3) and a mismatching public key (exit 1, nothing changed) all behave as described. It also ran in a folder with only the two key files.docker compose run --rm node decrypt-key: the normal start refused, a wrong password and then the right one gave the original plain key.🤖 Generated with Claude Code